package com.itheima.edu.info.manager.system.service;

import com.itheima.edu.info.manager.system.dao.TeacherDao;
import com.itheima.edu.info.manager.system.domain.Teacher;

/**
 * 操作老师业务的类
 */
public class TeacherService implements ITeacherService {


    //成员变量
    //操作老师数据的对象
    private TeacherDao dao= new TeacherDao();
    //增
    //入参 Teacher teacher
    //返回值没有
    public void xinZeng(Teacher teacher){
        dao.xinZeng(teacher);
    }

    //删
    public void shanChu(String id){
        dao.shanChu(id);

    }

    //改
    public void xiuGai(String id,Teacher teacher){
        dao.xiuGai(id, teacher);
    }

    //查

    public Teacher[] chaXunSuoYou(){

        Teacher[] teachers = dao.chaXunSuoYou();
        for (int i = 0; i < teachers.length; i++) {
            //有  直接返回
            if(teachers[i]!=null){
                return teachers;
            }
        }
        return null;
    }
    //判断学号是否存在
    //入参 String id
    //返回值 boolean
    public  boolean panDuan(String id){
        //先查询所有
        Teacher[] teachers = dao.chaXunSuoYou();
        //遍历比较
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if(teacher!=null&&teacher.getId().equals(id)){
                return true;
            }
        }
        return false;
    }


}
